#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
#   GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
#   Author :  Shawn.Tan
#   Date : 2025.10.28
#
#   History : Initial Version 2025.10.28
#
#
from ThreadDispatcher import ThreadDispatcher


#  A context manager to ensure the dispatcher lock acquire and release happen
#  reliably.
class ThreadRequestContextManager:
    def __init__(self):
        self.mDispatcher = ThreadDispatcher.getCurrentDispatcher()

    def __enter__(self):
        self.mDispatcher.request()
        return self

    def __exit__(self, *aUnused):
        self.mDispatcher.finish()
        return False
